# Author:	gong_libin
# Date:		2016_06_26

CC ?= g++
CFLAGS ?= -g -Wall

GLB_ENV ?= $(shell pwd)/..
GLB_BIN ?= $(GLB_ENV)/bin
GLB_INC ?= $(GLB_ENV)/inc
GLB_SRC ?= $(GLB_ENV)/src
GLB_UTL ?= $(GLB_ENV)/util
GLB_TST ?= $(GLB_ENV)/test

GLB_PLIB ?= /usr/lib
GLB_PINC ?= /usr/include/GlbInc

GLB_RLIB ?= /usr/local/lib
GLB_RINC ?= /usr/local/include/hiredis

GLB_XINC ?= /usr/include/libxml2
GLB_XLIB ?= `xml2-config --cflags --libs`

GLB_LIBS =					\
	-L$(GLB_PLIB) -lglbglobal		\
	-L$(GLB_PLIB) -lpthread			\
	-L$(GLB_RLIB) -lhiredis

GLB_OBJS =					\
	$(GLB_UTL)/GlbRtbBase.o			\
	$(GLB_UTL)/GlbRtbArea.o			\
	$(GLB_UTL)/GlbRtbAdvs.o			\
	$(GLB_UTL)/GlbRtbIdxs.o

GLBRTBAREATEST = GlbRtbAreaTest
GLBRTBADVSTEST = GlbRtbAdvsTest
GLBRTBIDXSTEST = GlbRtbIdxsTest
GLBRTBREDSTEST = GlbRtbRedsTest
GLBRTBADAPTER = GlbRtbAdapter

GLB_TARGETS =					\
	$(GLBRTBAREATEST)			\
	$(GLBRTBADVSTEST)			\
	$(GLBRTBIDXSTEST)			\
	$(GLBRTBREDSTEST)			\
	$(GLBRTBADAPTER)

GLB_OBJECTS =					\
	$(GLBRTBAREATEST).o			\
	$(GLBRTBADVSTEST).o			\
	$(GLBRTBIDXSTEST).o			\
	$(GLBRTBREDSTEST).o			\
	$(GLBRTBADAPTER).o

all: $(GLB_OBJECTS) $(GLB_TARGETS)

$(GLB_OBJECTS): %.o: %.cpp
	$(CC) -c $(CFLAGS) -I$(GLB_INC) -I$(GLB_PINC) -I$(GLB_RINC) -I$(GLB_XINC) $< -o $@

$(GLB_TARGETS): %: %.o
	$(CC) $(CFLAGS) $(GLB_XLIB) $(GLB_OBJS) $< -o $@ $(GLB_LIBS)

clean:
	rm -rf $(GLB_OBJECTS)
	rm -rf $(GLB_TARGETS)
